package org.nf.web.servlet.view;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletResponse;
import org.nf.web.servlet.BaseView;
import org.nf.web.servlet.ServletApi;

import java.io.IOException;

/**
 * @author wangl
 * @date 2024/5/21
 * 文本视图
 */
public class PlainView extends BaseView {

    private final String text;

    public PlainView(String text) {
        this.text = text;
    }

    @Override
    protected void render(ServletApi api) throws ServletException, IOException {
        HttpServletResponse response = api.response();
        response.setContentType("text/plain;charset=utf-8");
        response.getWriter().println(text);
    }
}